<?php

namespace App\Filament\Resources\BorrowRecordResource\Pages;

use App\Enums\BorrowStatus;
use App\Filament\Resources\BorrowRecordResource;
use App\Models\BorrowRecord;
use Filament\Actions;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;

class ListBorrowRecords extends ListRecords
{
    protected static string $resource = BorrowRecordResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\CreateAction::make()->label('借阅录入'),
        ];
    }

    public function getTabs(): array
    {
       $tabs =  collect(BorrowStatus::getFilterValue())->map(function ($value, $key) {
            return Tab::make($key)
                ->label($value)
                ->badge(BorrowRecord::where('returned',$key)->count())
                ->badgeColor(BorrowStatus::from($key)->getColor())
                ->modifyQueryUsing(function ($query) use ($key) {
                    return $query->where('returned', $key);
                });
        })->toArray();
        return  [
            'all' => Tab::make('全部'),
            ...$tabs,
        ];
    }
}
